#!/bin/bash

function test_gfx() {
    data_start="Process.*Execute"
    gfxinfo_raw=$(cat gfxinfo.txt)
    #    first_occur=$(grep "$data_start" -n gfxinfo.txt | head -n1 | awk -F: '{print $1}')
    #    sun_occur=$(grep -cn "$data_start" gfxinfo.txt )
    #    echo "sun_occur: ${sun_occur}"
    #    gfxinfo=$(echo -e "$gfxinfo_raw" | sed "$first_occur,$ { /$data_start/d}")
    #    echo "${gfxinfo}"

    gfx_info=${gfxinfo_raw}
    local sed_time=0
    local begin=0
    while IFS= read -r line; do
        line=$((line - sed_time * 3))
        begin=$((line - 2))
        echo "delete ${begin}-${line}"
        sed_time=$((sed_time + 1))
        gfx_info=$(echo -e "${gfx_info}" | sed "${begin},${line}d")
    done < <(grep "${data_start}" -n "${gfx_info}" | awk -F: '{print $1}')

    echo "gfx_info: ${gfx_info}"
}

function test_gfx_for() {
    data_start="Process.*Execute"
    gfxinfo_raw=$(cat gfxinfo.txt)
    gfx_info=${gfxinfo_raw}
    local sed_time=0
    local begin=0
    for line in $(grep "${data_start}" -n gfxinfo.txt | awk -F: '{print $1}'); do
        line=$((line - sed_time * 3))
        begin=$((line - 2))
        echo "delete ${begin}-${line}"
        sed_time=$((sed_time + 1))
        gfx_info=$(echo -e "${gfx_info}" | sed "${begin},${line}d")
    done
    echo "gfx_info: ${gfx_info}"
}

function test_aaa() {
    echo "begin test_aaa-----------------"
    data_start="not"
    line=$(grep "${data_start}" -n aaa | head -n1 | awk -F: '{print $1}')
    sed "${line},$ {/^$/{N;d} ; /${data_start}/{N;d}}" aaa
    #    echo "---------"
    #    aaa_info=$(cat aaa)
    #    echo -e "${aaa_info}" | sed "${line},$ {/^$/{N;d}; /${data_start}/{N;d}}" aaa
}

#test_gfx
test_gfx_for
# test_aaa
